/**
 * 
 */
Ext.ns("monitorManage");
monitorManage.init = function() {
	monitorManage.search_Id;// 搜索时选项
	monitorManage.big_Id;// 定义选定的大类型的序列号
	monitorManage.big_Name;// 定义选定的大类型名称
	monitorManage.Menu;
	monitorManage.MenuClick;
	monitorManage.photoPath;
	monitorManage.sm = new Ext.grid.CheckboxSelectionModel({
				handleMouseDown : Ext.emptyFn
			});
	monitorManage.cm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),
			monitorManage.sm, {
				header : '监考人员姓名',
				dataIndex : 'user_RealName',
				sortable : true
			}, {
				header : '监考人员员工号',
				dataIndex : 'monitor_Identity',
				sortable : true
			}, {
				header : '监考人员状态',
				dataIndex : 'monitor_State',
				renderer : function(value, celmeta, record) {
					var a = record.data["monitor_State"];
					if (a == 0) {
						return "未审核";
					} else {
						return "审核通过";
					}
				},
				sortable : true
			}, {
				header : '监考人员专业',
				dataIndex : 'monitor_Big.big_Name',
				sortable : true
			}, {
				header : '监考人员性别',
				dataIndex : 'user_Sex',
				sortable : true
			}, {
				header : '监考人员邮箱',
				dataIndex : 'monitor_Email',
				sortable : true
			}]);

	monitorManage.store = new Ext.data.JsonStore({
				url : 'conduction/showMonitorList',
				totalProperty : 'total',
				root : 'monitors',
				baseParams : {
					limit : 20
				},
				fields : [{
							name : "user_Id",
							mapping : 'user_Id',
							type : 'int'
						}, {
							name : "user_RealName",
							mapping : 'user_RealName',
							type : 'string'
						}, {
							name : "user_Sex",
							mapping : 'user_Sex',
							type : 'string'
						}, {
							name : "monitor_State",
							mapping : 'monitor_State',
							type : 'int'
						}, {
							name : "monitor_Identity",
							mapping : 'monitor_Identity',
							type : 'string'
						}, {
							name : "monitor_Phone",
							mapping : 'monitor_Phone',
							type : 'string'
						}, {
							name : "monitor_Email",
							mapping : 'monitor_Email',
							type : 'string'
						}, {
							name : "monitor_Big.big_Id",
							mapping : 'monitor_Big.big_Id',
							type : 'int'
						}, {
							name : "monitor_Big.big_Name",
							mapping : 'monitor_Big.big_Name',
							type : 'string'
						}]
			});
	monitorManage.BigTypes = new Ext.data.JsonStore({
				url : 'conduction/showBigList',
				totalProperty : 'total',
				root : 'bigs',
				fields : [{
							name : "big_Id",
							type : 'int'
						}, {
							name : "big_Name",
							type : 'string'
						}]
			});
	monitorManage.selecedItems = new Ext.data.JsonStore({
				url : 'public/showBigList',
						totalProperty : 'total',
						root : 'bigtypes',
						baseParams : {
							limit : 10
						},
						fields : [{
									name : "big_Id",
									type : 'int'
								}, {
									name : "big_Name",
									type : 'string'
								}]
			});
	monitorManage.Panel = new Ext.grid.GridPanel({
		deferredRender : true,
		sm : monitorManage.sm,
		cm : monitorManage.cm,
		store : monitorManage.store,
		loadMask : true,
		height : 450,
		viewConfig : {
			columnsText : '选择显示列',
			forceFit : true
		},
		tbar : new Ext.Toolbar(["-", {
					text : "查询审批注册监考人员",
					handler : function() {
						monitorManage.store.load({
									params : {
										start : 0,
										state : 0,
										search_Id : 0
									}
								});
					}
				}, '-', {
					text : '批量审批',
					handler : function() {
						var rows = monitorManage.Panel.getSelectionModel()
								.getSelections();
						if (rows.length < 1) {
							Ext.Msg.alert("提示", "请选择一个或多个选项！");
							return false;
						} else {
							var monitor_Ids = []; // 要删除的id
							Ext.each(rows, function(item) {
										monitor_Ids.push(item.data.user_Id);
									});
							Ext.Ajax.request({
								url : 'conduction/passState',
								method : 'post',
								params : {
									monitor_Ids : monitor_Ids,
									state : 1
								},
								success : function(response) {
									var obj = Ext.decode(response.responseText);
									if (obj.success == false) {
										Ext.Msg.alert("提示", obj.msg);
									} else {
										Ext.Msg.alert("提示", obj.msg);
									}
								},
								failure : function(response) {

								}
							});
						}
					}
				}, '-', {
					id : 'monitor_Type',
					allowBlank : false,
					emptyText : '请选择专业进行查询',
					blankText : '对不起，请选择专业！',
					xtype : 'combo',
					mode : 'remote',
					triggerAction : 'all',
					valueField : 'big_Id',
					displayField : 'big_Name',
					pageSize : 8,
					minListWidth : 300,
					store : monitorManage.BigTypes
				}, '-', {
					text : '增加监考人员',
					handler : function() {
						if (monitorManage.addWindow.isVisible()) {
							monitorManage.addWindow.hide(this, function() {

									});
						} else {
							monitorManage.addWindow.show(this, function() {

									});
						}
					}
				}, "-", {
					text : "显示所有监考人员",
					handler : function() {
						monitorManage.store.load({
									params : {
										start : 0,
										state : 1
									}
								});
					}
				}, '-', {
					id : 'search_Type',
					allowBlank : false,
					emptyText : '请选择查询的类型',
					blankText : '对不起，请选择查询类型',
					xtype : 'combo',
					mode : 'local',
					valueField : 'search_Id',
					displayField : 'search_Name',
					triggerAction : 'all',
					store : new Ext.data.ArrayStore({
								id : 0,
								fields : ['search_Id', 'search_Name'],
								data : [[1, '监考人员名称'], [2, '监考人员员工号']]
							}),
					listeners : {
						'select' : function(combo) {
							monitorManage.search_Id = combo.getValue();
						}
					}
				}, new Ext.ux.form.SearchField({
							emptyText : '请输入信息进行模糊查询',
							store : monitorManage.store,
							width : 220,
							onTrigger2Click : function() {
								var v = this.getRawValue();
								if (v.length < 1) {
									this.onTrigger1Click();
									return;
								}
								var o = {
									start : 0,
									search_Id : monitorManage.search_Id
								};
								this.store.baseParams = this.store.baseParams
										|| {};
								this.store.baseParams[this.paramName] = v;
								this.store.reload({
											params : o
										});
								this.hasSearch = true;
								this.triggers[0].show();
							}
						})]),
		bbar : new Ext.PagingToolbar({
					id : 'monitorManage.pagetool',
					pageSize : 10,
					store : monitorManage.store,
					displayInfo : true,
					displayMsg : '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
					emptyMsg : "没有记录"
				})
	});
	monitorManage.addPanel = new Ext.FormPanel({
				defaultType : 'textfield',
				width : 700,
				labelAlign : 'center',
				constrain : true,
				constrainHeader : true,
				bodyStyle : {
					padding : '20px'
				},
				viewConfig : {
					forceFit : true
				},
				items : [{
							fieldLabel : '员工号',
							allowBlank : false,
							blankText : '对不起，请填写员工号！',
							emptyText : '请填写员工号',
							msgTarget : 'side',
							minLength : 6,
							minLengthText : '请输入员工号大于6个字符',
							maxLength : 15,
							maxLengthText : '请输入员工号小于15个字符',
							name : 'monitor.monitor_Identity'
						}, {
							fieldLabel : '性别',
							allowBlank : false,
							emptyText : '请选择对方性别',
							blankText : '对不起，请选择对方性别',
							xtype : 'combo',
							mode : 'local',
							valueField : 'sex',
							displayField : 'name',
							triggerAction : 'all',
							name : 'monitor.user_Sex',
							store : new Ext.data.ArrayStore({
										id : 0,
										fields : ['sex', 'name'],
										data : [['男', '男'], ['女', '女']]
									})
						}, {
							fieldLabel : '真实姓名',
							emptyText : '请填写真实姓名',
							msgTarget : 'side',
							allowBlank : false,
							blankText : '对不起，真实姓名不能为空',
							name : 'monitor.user_RealName'
						}, {
							fieldLabel : '所学专业',
							allowBlank : false,
							emptyText : '请选择专业进行查询',
							blankText : '对不起，请选择专业！',
							xtype : 'combo',
							mode : 'remote',
							triggerAction : 'all',
							valueField : 'big_Id',
							displayField : 'big_Name',
							minListWidth : 150,
							store : monitorManage.selecedItems,
							listeners : {
								'select' : function(combo) {
									monitorManage.search_Id = combo.getValue();
								}
							}
						}, {
							fieldLabel : '邮箱',
							msgTarget : 'side',
							vtype : "email",
							emptyText : '请填写邮箱地址',
							name : 'monitor.monitor_Email'
						}],
				buttonAlign : 'center',
				buttons : [{
					text : '提交',
					handler : function() {
						if (monitorManage.addPanel.getForm().isValid()) {
							monitorManage.addPanel.getForm().submit({
								url : 'conduction/addMonitor',
								params : {
										big_Id : monitorManage.search_Id 
									},
								method : 'post',
								waitMsg : '请稍候，正在处理数据.....',
								waitTitle : '提示',
								success : function(form, action) {
									if (action.result.success == true) {
										Ext.Msg.alert("提示", action.result.msg);
										monitorManage.addPanel.getForm()
												.reset();
									} else {
										Ext.Msg.alert("提示", action.result.msg);
									}
								},
								failure : function(form, action) {
									Ext.Msg.alert('提示', "服务器连接失败！！！！");
								}
							});
						}
					}
				}, {
					text : '重置',
					handler : function() {
						monitorManage.addPanel.getForm().reset();
					}

				}]
			});
	monitorManage.Menu = new Ext.menu.Menu({
		id : 'monitorManage_Menu',
		items : [{
			text : "查看详情",
			handler : function() {
				monitorManage.photoPath = "conduction/showMonitorPhoto?monitor_Id="
						+ new String(monitorManage.MenuClick.get("user_Id"));
				monitorManage.showPanel = new Ext.FormPanel({
							defaultType : 'displayfield',
							width : 700,
							labelAlign : 'center',
							constrain : true,
							constrainHeader : true,
							bodyStyle : {
								padding : '30px'
							},
							viewConfig : {
								forceFit : true
							},
							items : [{
								fieldLabel : '姓名',
								value : monitorManage.MenuClick
										.get("user_RealName")
							}, {
								fieldLabel : '工作证号',
								value : monitorManage.MenuClick
										.get("monitor_Identity")
							}, {
								fieldLabel : '所学专业',
								value : monitorManage.MenuClick
										.get("monitor_Big.big_Name")
							}, {
								fieldLabel : '性别',
								value : monitorManage.MenuClick.get("user_Sex")
							}, {
								fieldLabel : '手机号',
								value : monitorManage.MenuClick
										.get("monitor_Phone")
							}, {
								fieldLabel : '邮箱',
								value : monitorManage.MenuClick
										.get("monitor_Email")
							}, {
								inputType : 'image',
								autoCreate : {
									tag : "input",
									type : "image",
									src : monitorManage.photoPath
								},
								width : 120,
								height : 140,
								fieldLabel : '照片'
							}],
							buttonAlign : 'center',
							buttons : [{
										text : '退出',
										handler : function() {
											monitorManage.showWindow.close();
										}

									}]
						});

				monitorManage.showWindow = new Ext.Window({
							title : '监考人员详细信息窗口',
							width : 700,
							autoHeight : true,
							modal : true,
							resizable : false,
							animateTarget : 'target',
							items : [monitorManage.showPanel]
						});
				monitorManage.showWindow.show();
			}
		}, {
			text : '审核通过',
			handler : function() {
				Ext.Ajax.request({
							url : 'conduction/passState',
							method : 'post',
							params : {
								monitor_Ids : monitorManage.MenuClick
										.get("user_Id"),
								state : 1
							},
							success : function(response) {
								var obj = Ext.decode(response.responseText);
								if (obj.success == false) {
									Ext.Msg.alert("提示", obj.msg);
								} else {
									Ext.Msg.alert("提示", obj.msg);
								}
							},
							failure : function(response) {

							}
						});
			}
		}, {
			text : '停止监考',
			handler : function() {
				Ext.Ajax.request({
							url : 'conduction/defuseState',
							method : 'post',
							params : {
								monitor_Ids : monitorManage.MenuClick
										.get("user_Id"),
								state : 2
							},
							success : function(response) {
								var obj = Ext.decode(response.responseText);
								if (obj.success == false) {
									Ext.Msg.alert("提示", obj.msg);
								} else {
									Ext.Msg.alert("提示", obj.msg);
								}
							},
							failure : function(response) {
							}
						});
			}
		}]
	});
	monitorManage.Main = new Ext.Panel({
				title : '监考人员管理',
				id : 'monitorManagerPanel',
				frame : true,
				deferredRender : true,
				closeAction : 'hide',
				cm : monitorManage.cm,
				store : monitorManage.store,
				loadMask : true,
				autoWidth : true,
				// autoHeight : true,
				closable : true,
				layout : 'fit',
				viewConfig : {
					forceFit : true
				},
				items : [monitorManage.Panel]
			});
	monitorManage.addWindow = new Ext.Window({
				title : '增加监考人员信息窗口',
				width : 700,
				autoHeight : true,
				modal : true,
				resizable : false,
				draggable : false,
				closeAction : 'hide',
				animateTarget : 'target',
				items : [monitorManage.addPanel]
			});
	Ext.getCmp("monitor_Type").on('select', function(combo) {
				monitorManage.store.load({
							params : {
								start : 0,
								state : 0,
								big_Id : combo.getValue()
							}
						});
			});
	monitorManage.Panel.on("rowcontextmenu", function(grid, rowIndex, e) {
				e.preventDefault();
				monitorManage.Panel.getSelectionModel().selectRow(rowIndex);
				monitorManage.Menu.showAt(e.getXY());
				monitorManage.MenuClick = monitorManage.Panel
						.getSelectionModel().getSelected(rowIndex);
			});
};
Ext.onReady(monitorManage.init);